package com.file.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.entity.Customer;
import com.entity.CustomerMeter;
import com.entity.CustomerMeterPK;
import com.entity.Meter;
import com.file.entity.FileCustomer;
import com.file.entity.FileCustomerMeter;
import com.file.entity.FileMeter;
import com.file.service.CustomerMeterService;
import com.file.service.CustomerService;
import com.file.service.MeterService;
import com.utils.JsonResult;

/**
 * @Title: CustomerMeterController.java
 * @Package com.file.controller
 * @author 孙梦楠
 * @date 2017年7月31日 上午10:31:07
 * @version V1.0.0
 */

@RestController
@RequestMapping(value = "/file/customermeter")
public class CustomerMeterController {
	
	
	private static final Logger log = LoggerFactory.getLogger(CustomerMeterController.class);


	@Autowired
	private CustomerMeterService customermeterservice;

	@Autowired
	private MeterService meterservice;

	@Autowired
	private CustomerService customerservice;

	
	// 条件列表
	@RequestMapping(value = "", method = RequestMethod.POST)
	public JsonResult<List<FileCustomerMeter>> listcustomermeter(@RequestBody Customer customer,
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {
		
		String customeraccount = customer.getCustomeraccount();
		String customername = customer.getCustomername();
		String customeraddress = customer.getCustomeraddress();
		

		return customermeterservice.ListcustomermeterByConditions(customeraccount, customername, customeraddress,opeorgcookie,languagecookie,opetypecookie);
	}

	// 列出所有待用的表
	@RequestMapping(value = "/listnotinstallmeter", method = RequestMethod.GET)
	public JsonResult<List<FileMeter>> listallmeter(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		return meterservice.listallmeter(opeorgcookie, opetypecookie,"1", 272, "列出所有待用的表",languagecookie);
	}

	// 列出所有没有关联表的用户
	@RequestMapping(value = "/listnotinstallcustomer", method = RequestMethod.GET)
	public JsonResult<List<FileCustomer>> listallcustomer(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		return customerservice.listallcustomer(opeorgcookie, "1", 273, "列出所有没有连接表的用户",languagecookie);
	}

	// 增加关联
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public JsonResult<CustomerMeter> addcustomermeter(@RequestBody CustomerMeterPK customermeterpk) {

		Integer customerid = customermeterpk.getCustomerid();
		Integer meterid = customermeterpk.getMeterid();

		return customermeterservice.addcustomermeter(customerid, meterid);

	}

	// 删除关联关系
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public JsonResult<CustomerMeter> deletecustomermeter(@RequestBody CustomerMeterPK customermeterpk,
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie) {
		Integer customerid = customermeterpk.getCustomerid();

		return customermeterservice.deletecustomermeter(customerid,opeorgcookie,opetypecookie);

	}

	// 查询单个（修改界面）
	@RequestMapping(value = "/getbyid", method = RequestMethod.POST)
	public JsonResult<CustomerMeter> updateviewcustomermeter(
			@RequestBody CustomerMeterPK customermeterpk) {
		
		Integer customerid = customermeterpk.getCustomerid();
		Integer meterid = customermeterpk.getMeterid();

		return customermeterservice.updateviewcustomermeter(customerid, meterid);
	}

}
